<?php
defined('_JEXEC') or die( 'Restricted access' );

jimport( 'joomla.application.component.view');

class igcategoriesViewAdd_edit_category extends JView
{
	function display($tpl = null)
	{
	    global $mainframe;
	    
		$model =& $this->getModel();
		
		$category =& $this->get('Data');
		
		
		if($category->parent != 0)
		{
			$parentCategory =& $model->getCategory($category->parent);
			$profile =& $model->getProfile($parentCategory->profile);
		}
		else
		{
			$profile  =& $model->getProfile($category->profile);
		}
		
		
		if(empty($category->id))
		{
			JToolBarHelper::title(JText::_('NEW CATEGORY'),'generic.png');
		}
		else
		{
			JToolBarHelper::title( JText::_('EDIT CATEGORY').' - '.$category->name );
			JToolBarHelper::apply();
		}
		JToolBarHelper::save();
		JToolBarHelper::cancel();
		
       
		if( !empty($category->menu_image_filename) )
		{
                    //QUOCTUAN261 - add try catch
                    try{
                        if(! $fileArray = igFileHelper::originalToResized($category->menu_image_filename, $profile->menu_max_width, 
                        $profile->menu_max_height, $profile->img_quality, $profile->crop_menu, 0, $profile->round_menu, $profile->round_fill) )
                        {
                            return false;
                        }
                    }
                    catch(Exception $e){
                        return false;
                    }
		    
		    
		    $this->assignRef('folderName', $fileArray['folderName']);
		    $this->assignRef('fullFileName', $fileArray['fullFileName']);
		}
        
        //make the html form items
        $lists = array();
        $lists['parentSelectList'] = igHtmlHelper::getCategorySelect('parent', 'value', 'text', $category->id, false, true, 10, false, $category->parent);
        $lists['published'] = JHTML::_('select.booleanlist',  'published', 'class="inputbox"', $category->published );
		$lists['remove_menu_image'] = JHTML::_('select.booleanlist',  'remove_menu_image', 'class="inputbox"', 0 );
        $lists['user'] = igHtmlHelper::getUserList($category->user);
		$lists['profiles'] = igHtmlHelper::getProfileList($category->profile);
        

		$this->assignRef('lists',   $lists);
		$this->assignRef('profile',	$profile);
		$this->assignRef('category',$category);

		parent::display($tpl);
	}
}